﻿using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLLA
{
    public partial class Order_FlowOrganization_T : BaseBLL<Model.Order_FlowOrganization_T>, IBLL.IOrder_FlowOrganization_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        IBLL.IBLLSession bl = DI.SpringHelper.GetObject<IBLL.IBLLSession>("BLLSession");
        public string GetOrgListFromMer(int pageIndex, int pageSize, string MerID, string StarTime, string EndTime,int Flat, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务流程
            //int total = 0;
            List<Model.View_Order_FlowOrganization> OrgList = new List<Model.View_Order_FlowOrganization>();
            try
            {
                // OrgList = base.GetPagedList<int>(pageIndex, pageSize, ref total, u => u.MerID == MerID, u => u.OrgID);
                StringBuilder sql = new StringBuilder();
                if (Flat != 2)
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where MerID='" + MerID + "' and Flat=" + Flat);
                }
                else
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where MerID='" + MerID + "' ");
                }
                if (StarTime.Trim() != "")
                {
                    sql.Append(" and  OrgFlowTime > '" + StarTime + "' ");
                }
                if (EndTime.Trim() != "")
                {
                    sql.Append(" and OrgFlowTime < '" + EndTime + "'");
                }
                OrgList = base.DBSession.IView_Order_FlowOrganizationDAL.GetListBy(sql.ToString());
                result.total = OrgList.Count;
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }

            if (OrgList != null && OrgList.Count != 0)
            {
                result.BS = "1";
                result.Msg = "查询成功！";
                result.rows = OrgList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            }
            else
            {
                result.BS = "0";
                result.Msg = "查询不到数据！";
            }
            return os.StringOfObject(result, RETID);
            #endregion
        }

        public string GetOrgListFromOrg(int pageIndex, int pageSize, int OrgID, string StarTime, string EndTime, int Flat, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务流程
            //int total = 0;
            List<Model.View_Order_FlowOrganization> OrgList = new List<Model.View_Order_FlowOrganization>();
            try
            {

                //OrgList = base.GetPagedList<int>(pageIndex, pageSize, ref total, u => u.OrgID == OrgID, u => u.OrgID);
                //OrgList = base.GetListBy("SELECT * FROM Order_FlowOrganization_T where OrgID=" + OrgID + " and  OrgFlowTime > '" + StarTime + "' and OrgFlowTime < '" + StarTime + "' ");
                StringBuilder sql = new StringBuilder();
                //sql.Append("SELECT * FROM View_Order_FlowOrganization where  OrgID=" + OrgID+" and Flat="+ Flat);
                if (Flat != 2)
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where OrgID=" + OrgID + " and Flat=" + Flat);
                }
                else
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where OrgID=" + OrgID + " ");
                }
                if (StarTime.Trim() != "")
                {
                    sql.Append(" and  OrgFlowTime > '" + StarTime + "' ");
                }
                if (EndTime.Trim() != "")
                {
                    sql.Append(" and OrgFlowTime < '" + EndTime + "'");
                }
                OrgList = base.DBSession.IView_Order_FlowOrganizationDAL.GetListBy(sql.ToString());
                result.total = OrgList.Count;
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }

            if (OrgList != null && OrgList.Count != 0)
            {
                result.BS = "1";
                result.Msg = "查询成功！";
                result.rows = OrgList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            }
            else
            {
                result.BS = "0";
                result.Msg = "查询不到数据！";
            }
            return os.StringOfObject(result, RETID);
            #endregion
        }



        /// <summary>
        /// 查询企业账号流水
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="MerID">商户ID</param>
        /// <param name="OrgID">企业账户ID</param>
        /// <param name="StarTime">yyyyMMddHHmmss</param>
        /// <param name="EndTime">yyyyMMddHHmmss</param>
        /// <param name="Flat">0未平账/1平账/2所有</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrgFlowListFrom(int pageIndex, int pageSize, string MerID, int OrgID, string StarTime, string EndTime, int Flat, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务流程
            //int total = 0;
            List<Model.View_Order_FlowOrganization> OrgList = new List<Model.View_Order_FlowOrganization>();
            try
            { 
                StringBuilder sql = new StringBuilder();
               // sql.Append("SELECT * FROM View_Order_FlowOrganization where  OrgID=" + OrgID + " and MerID='" + MerID + "' and Flat=" + Flat);
                if (Flat != 2)
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where OrgID=" + OrgID + " and MerID='" + MerID + "' and Flat=" + Flat);
                }
                else
                {
                    sql.Append("SELECT * FROM View_Order_FlowOrganization where OrgID=" + OrgID + "  and MerID='" + MerID + "'");
                }
                if (StarTime.Trim() != "")
                {
                    sql.Append(" and  OrgFlowTime > '" + StarTime + "' ");
                }
                if (EndTime.Trim() != "")
                {
                    sql.Append(" and OrgFlowTime < '" + EndTime + "'");
                }
                OrgList = base.DBSession.IView_Order_FlowOrganizationDAL.GetListBy(sql.ToString());
                result.total = OrgList.Count;
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }

            if (OrgList != null && OrgList.Count != 0)
            {
                result.BS = "1";
                result.Msg = "查询成功！";
                result.rows = OrgList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            }
            else
            {
                result.BS = "0";
                result.Msg = "查询不到数据！";
            }
            return os.StringOfObject(result, RETID);
            #endregion
        }
    }
}
